import React, { Component } from 'react';
import { Input, InputNumber, Button, Form, Modal } from 'antd';
import styles from './ChargeManage.less'
import { connect } from 'dva'
const FormItem = Form.Item;
@connect(({ login }) => ({
  login
}))
class Gift extends Component {
  constructor(props) {
    super(props)
    this.state = {
      isRevise: true,
    }
  }

  onHandleSave = () => {
    const { validateFields, getFieldsValue } = this.props.form
    const { giftItem } = this.props
    validateFields(errors => {
      if (errors) {
        return;
      }
      const data = {
        ...getFieldsValue(),
        id: giftItem && giftItem.id
      };

      Modal.confirm({
        title: '确定要修改此项目?',
        okText: '确定',
        cancelText: '取消',
        onOk: () => {
          this.setState({ isRevise: true })
          this.props.onGiftReviseOk && this.props.onGiftReviseOk(data);
        },
      });
    });
  }

  onHandleRevise = () => {
    console.log(111)
    this.setState({ isRevise: false })
  }


  render() {
    const { getFieldDecorator } = this.props.form
    const { giftItem, } = this.props
    const { isRevise } = this.state
    const { isAdmin } = this.props.login
    console.log('aa', isAdmin)
    return (
      <div className={styles.ChargeManage}>
        <Form>
          <ul>
            <li>
              <ul>
                <li><span>积分兑换礼券比例</span></li>
                <li><span>积分</span></li>
                <li>
                  <FormItem >
                    {getFieldDecorator('bonous', {
                      initialValue: giftItem && giftItem.bonous,
                    })(
                      <InputNumber disabled={isRevise} min={0} />
                    )}
                  </FormItem>
                </li>
                <li><span>:</span></li>
                <li><span>礼券</span></li>
                <li>
                  <FormItem >
                    {getFieldDecorator('glft', {
                      initialValue: giftItem && giftItem.glft,
                    })(
                      <InputNumber disabled={isRevise} min={0} />
                    )}
                  </FormItem>
                </li>
              </ul>
            </li>
            <li>
              <ul>
                <li><span>客户端提示文字</span></li>
                <li>
                  <FormItem >
                    {getFieldDecorator('tip', {
                      initialValue: giftItem && giftItem.tip,
                    })(
                      <Input disabled={isRevise} style={{ width: '400px' }} />
                    )}
                  </FormItem> </li>
                <li><span style={{ color: 'red' }}>最多输入28字</span></li>
              </ul>
            </li>
          </ul>
        </Form>
        <div>

        </div>
        {isAdmin ? <Button type="primary" ghost onClick={isRevise ? this.onHandleRevise : this.onHandleSave}>{isRevise ? "编辑" : "保存"}</Button> : <div></div>}
      </div>
    );
  }
}

export default connect(({ login }) => ({ login }))(Form.create()(Gift));
